<!DOCTYPE html>
<html class="x-admin-sm">

<head>
  <meta charset="UTF-8">
  <title>种类管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
    content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  <link rel="stylesheet" href="../../css/font.css">
  <link rel="stylesheet" href="../../css/xadmin.css">
  <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script src="../../lib/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="../../js/xadmin.js"></script>
  <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
</head>

<body>
  <div class="x-nav">
    <span class="layui-breadcrumb">
      <a href="">首页</a>
      <a href="">演示</a>
      <a>
        <cite>导航元素</cite></a>
    </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
      onclick="location.reload()" title="刷新">
      <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
  </div>
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-body ">
            <blockquote class="layui-elem-quote">
               <button class="layui-btn layui-btn-warm layui-btn-xs" onclick="xadmin.open('添加新种类','add.html', 500, 400)"><i
                class="layui-icon">&#xe642;</i>添加新种类</button>
            </blockquote>

            <hr>
            <!--chengjisendeform-->
            <form class="layui-form form-position layui-form-pane" style="margin: 0;" action="" lay-filter="Form"
              id="Form" name="Form">
              <div class="layui-form-item">
                <label class="layui-form-label">选择物品</label>
                <div class="layui-input-inline layui-show-xs-block">
                  <select name="category" id="category" lay-filter="category">
                    <option value=""></option>
                  </select>
                </div>
                <div class="layui-input-inline layui-show-xs-block">
                  <select name="typical" id="typical" lay-filter="typical">

                  </select>
                </div>
                <div class="layui-input-inline layui-show-xs-block" style="">
                  <select name="brand" id="brand" lay-filter="brand">

                  </select>
                </div>

                <div class="layui-input-inline layui-show-xs-block">
                  <select name="typicalId" id="model" lay-filter="model">

                  </select>
                </div>

                <div class="layui-inline layui-show-xs-block">
                  <button class="layui-btn layui-btn-danger" lay-submit="" lay-filter="search" type="button"
                    id="search"><i class="layui-icon">&#x1005;</i>搜索</button>
                </div>
              </div>
            </form>
            
          </div>

          <div class="layui-card-body">
            <table class="layui-table layui-form" id="demo">
              <thead id="thead" class="layui-hide">
                <tr>
                  <th>序号</th>
                  <th class="type">设备类型</th>
                  <th class="name">设备名称</th>
                  <th class="brand">品牌</th>
                  <th class="model">型号</th>
                  <th>数量</th>
                  <th class="unit">单位</th>
                  <th>库存状态</th>
                  <th style="text-align: center;">操作</th>
                </tr>
              </thead>
              <tbody class="tbody">

              </tbody>
            </table>
          </div>
        </div>
      </div>
    </div>
  </div>
  <script type="text/javascript" src="../../js/jquery.min.js"></script>
  <script type="text/javascript" src="../../js/app.js"></script>
  <script type="text/javascript" src="cateSelect.js"></script>
  <script>
    var managerId = app.getManagerId()
    //获取所有类别
    // 步骤一：
    function resultCate(id) {
      return $.ajax({
        type: 'get',
        url: 'http://60.205.182.15:8080/inventory/v1/type/getTypicalByCategoryId/' + id + '?managerId=' + managerId,
        dataType: 'json',
        success: function (res) {
          // return res
        },
        error: function (err) {
          console.log(err)
        }
      })
    }

    $x_cate = $(".x-cate")
    $.ajax({
      type: 'get',
      url: 'http://60.205.182.15:8080/inventory/v1/type/getAllCategory',
      dataType: 'json',
      success: function (res) {
        var tbody
        var i = 1
        res.objs[0].forEach(item => {

          resultCate(item.categoryId).then(data => {
            data.objs[0].forEach(datas => {
              var str = `
							  <tr>
								<td>
                    <input type="checkbox" name="" lay-skin="primary"><div class="layui-unselect layui-form-checkbox" id="select${datas.typicalId}" lay-skin="primary"><i class="layui-icon layui-icon-ok" onclick="layuiSelect('${datas.typicalId}')"></i></div>
                  </td>
                  <td>${i++}</td>
                  <td>${item.categoryName}</td>
                  <td>${datas.typicalName}</td>
                  <td>${datas.brand}</td>
								  <td>${datas.typicalModel}</td>
								  <td>${datas.inRepository == null ? '/':datas.inRepository}</td>
								  <td>${datas.unit}</td>
                  <td class="td-manage" style="display: flex;justify-content: space-between;"> 
                    
                    <a title="编辑"  onclick="xadmin.open('编辑','admin-edit-cate.html?${datas.typicalId}&${datas.brand}&${datas.unit}&${datas.typicalName}&${datas.typicalModel}&${item.categoryName}')" href="javascript:;">
                      <i class="layui-icon">&#xe642;</i>
                      <span>修改信息</span>
                    </a> 
                    <a title="删除" onclick="memberdel('${datas.typicalId}')">
                      <i class="layui-icon">&#xe640;</i>
                      <span>删除</span>
                    </a>
                  </td>
                </tr>
							`
              tbody += str
            })

            $(".tbody").html(tbody)
          })

        });
      },
      error: function (err) {
        console.log(err)
      }
    })

    layui.use(['form'], function () {
      form = layui.form;

    });

    /*用户-删除*/
    function memberdel(id) {
      layer.confirm('确认要删除吗？', function (index) {
        $.ajax({
          type: 'get',
          url: app.ServerUrl + 'v1/repository/deleteSpecificThinsById' + id,
          dataType: 'json',
          success: function (res) {
            alert("删除成功")
            window.location.href = 'cate.html'
          },
          error: function (err) {
            console.log(err)
          }
        })
      })
    }
    // 分类展开收起的分类的逻辑

    $(function () {
      $("tbody.x-cate tr[fid!='0']").hide();
      // 栏目多级显示效果
      $('.x-show').click(function () {
        if ($(this).attr('status') == 'true') {
          $(this).html('&#xe625;');
          $(this).attr('status', 'false');
          cateId = $(this).parents('tr').attr('cate-id');
          $("tbody tr[fid=" + cateId + "]").show();
        } else {
          cateIds = [];
          $(this).html('&#xe623;');
          $(this).attr('status', 'true');
          cateId = $(this).parents('tr').attr('cate-id');
          getCateId(cateId);
          for (var i in cateIds) {
            $("tbody tr[cate-id=" + cateIds[i] + "]").hide().find('.x-show').html('&#xe623;').attr('status',
              'true');
          }
        }
      })
    })


    var cateIds = [];

    function getCateId(cateId) {
      $("tbody tr[fid=" + cateId + "]").each(function (index, el) {
        id = $(el).attr('cate-id');
        cateIds.push(id);
        ss
        getCateId(id);
      });
    }

    //实现点击选择事件
    function layuiSelect(e) {
      $(`#select${e}`).addClass("layui-form-checked")
    }

    //实现批量删除功能
    function delall() {
      layer.confirm('确认要删除吗？', function (index) {
        if ($(".layui-form-checked").length != 0) {
          var a = ''
          for (var i = 0; i < $(".layui-form-checked").length; i++) {
            var str = `typesId=${$(".layui-form-checked")[i].id.split("select")[1]}&`
            a += str
          }
          $.ajax({
            type: 'delete',
            url: 'http://60.205.182.15:8080/inventory/v1/type/deleteMaterialByArray?' + a,
            dataType: 'json',
            success: function (res) {
              if (res.resultStatus == -1) {
                alert("删除失败，该记录仍存在子目录，无法删除")
                window.location.href = 'cate.html'
              } else {
                alert("删除成功")
                window.location.href = 'cate.html'
              }
            },
            error: function (err) {
              console.log(res)
            }
          })
        } else {
          alert("请选择删除项")
          window.location.href = 'cate.html'
        }
      })
    }
  </script>
</body>


</html>